package net.caixiaomi.info.Lottery.presenter;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;

import net.caixiaomi.info.Lottery.callback.TrendCallBack;
import net.caixiaomi.info.Lottery.model.LotteryTrendParamsEntity;
import net.caixiaomi.info.Lottery.model.TrendChartData;
import net.caixiaomi.info.Lottery.trend.data.TrendData;
import net.caixiaomi.info.model.BaseCallModel;
import net.caixiaomi.info.net.RequestService;
import net.caixiaomi.info.net.ResponseCallback;
import net.caixiaomi.info.net.ResponseError;
import net.caixiaomi.info.net.RetrofitManage;

import java.util.ArrayList;

/**
 * Created by suntian on 2018/8/16.
 */

public class LotteryTrendPresenter {

//    private int compute=1;  //0不统计，1统计
//    private int count=100;  //期数，30，50，100
//    private int drop=1;   //是否显示遗漏0不显示，1显示
//    private int sort=0;   //排序, 0正序1倒序

    private boolean mBottomVisible;

    private TrendCallBack mCallBack;
    private LotteryTrendParamsEntity mParams;

    public LotteryTrendPresenter(TrendCallBack mCallBack) {
        this.mCallBack = mCallBack;
        mParams=new LotteryTrendParamsEntity();
        mParams.setCompute(1);
        mParams.setCount(100);
        mParams.setSort(0);
        mParams.setDrop(1);
    }

    public LotteryTrendParamsEntity getmParams() {
        return mParams;
    }

    public void setmParams(LotteryTrendParamsEntity mParams) {
        this.mParams = mParams;
        mBottomVisible=mParams.getCompute()==0?true:false;
    }

    public boolean getBottomVisible(){
        return mBottomVisible;
    }

    public void setParams(String msg){
        String[]msgs=msg.split(",");
        mParams.setCompute(Integer.parseInt(msgs[2]));
        mParams.setCount(Integer.parseInt(msgs[0]));
        mParams.setSort(Integer.parseInt(msgs[1]));
        mParams.setDrop(Integer.parseInt(msgs[3]));
        mBottomVisible=Integer.parseInt(msgs[2])==0?true:false;
        loadData();
    }

    public void loadData() {
        JSONObject params = new JSONObject();
        params.put("compute", mParams.getCompute());
        params.put("count", mParams.getCount());
        params.put("drop", mParams.getDrop());
        params.put("sort", mParams.getSort());
        params.put("tab", 0);
        RequestService requestService = RetrofitManage.getInstance().getRequestService();
        retrofit2.Call<BaseCallModel<TrendChartData>> baseCallModelCall = requestService.getChartData(params);
        baseCallModelCall.enqueue(new ResponseCallback<BaseCallModel<TrendChartData>>() {
            @Override
            public void onSuccess(BaseCallModel<TrendChartData> data) {
                TrendChartData entity=data.data;
                mCallBack.setTrendData(entity);
            }

            @Override
            public void onFail(ResponseError error) {

            }

            @Override
            public void onError() {

            }
        });
    }
}
